*	--------------------------------------------------------------------------------------------------------
*	-- SPECIFY DIRECTORY PATH HERE. It is the folder where this master.do file is located ----------------------------------------------------------------
*	--------------------------------------------------------------------------------------------------------
	global dir 	"C:\Users\...\data_and_codes"	
*	---------------------------------------------------------------------------------------------------------
	// Data:
	global data			"${dir}\data"
	
	clear all
	log close _all
	set more off
	global year		09 
	// Macros specific to the rdrobust command:
	global bwc	msetwo					// BW Method={mserd; msetwo}
	global bwr	h_msetwo_r				// BW right={h_mserd; h_msetwo_r}
	global bwl	h_msetwo_l				// BW right={h_mserd; h_msetwo_r}

// 	TABLE 1: Internal validity test: placebo experiment
	use "$data/plcb_07_08.dta", clear
	// Pooled
	rdrobust ins0708	force_shift		, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) ///
	covs(comm1 comm2	comm3	comm4	comm5	comm6	comm7	comm8	comm9	comm10	comm11	comm12	comm13	comm14	comm15	comm17	comm18	comm20	comm22	comm23	comm24	comm26	comm27	comm28 comm29	comm30 comm31	comm32	comm33	comm34	comm35 	comm36	comm37	comm38	comm39	comm40	comm41	comm42	comm43	comm44	comm45	comm46	comm47	comm48 comm49)
	// Rural
	rdrobust ins0708	force_shift		if rural==1 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) ///
	covs(comm2	comm3	comm4	comm5	comm6	comm7	comm8	comm9	comm10	comm11	comm12	comm13	comm14	comm15	comm17	comm18	comm20	comm22	comm23	comm24	comm26	comm27	comm28)
	// Urban	
	rdrobust ins0708	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) ///
	covs(comm29	comm30 comm31	comm32	comm33	comm34	comm35 	comm36	comm37	comm38	comm39	comm40	comm41	comm42	comm43	comm44	comm45	comm46	comm47	comm48 comm49)

// TABLE 2: Internal validity. RDD balancing tests
	foreach y in 	hh_size share_fem 	any_edu hoh_nagri  wdw_hhh_male fem_head eld_hhh_male eld_hhh_fem  {
	use "$data/bal_09_10.dta", clear
	g depvar = `y'
	display "-------------"
	display "`y'"
	display "-------------"
	// Pooled
	rdrobust depvar	force_shift, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) ///
	covs(comm1 comm2	comm3	comm4	comm5	comm6	comm7	comm8	comm9	comm10	comm11	comm12	comm13	comm14	comm15	comm16 comm17	comm18	comm19 comm20	comm21 comm22	comm23	comm24	comm25 comm26	comm27	comm28 	comm29	comm30 comm31	comm32	comm33	comm34	comm35 	comm36	comm37	comm38	comm39	comm40	comm41	comm42	comm43	comm44	comm45	comm46	comm47	comm48 comm49)
	}
	
	use "$data/pld_09_10.dta", clear
*	TABLE 3: Subsidization and Enrollment
	preserve
	// a) Extensive margin (Columns 1-3) 
	duplicates drop year hhid, force	// trimm down towards household level
	/* Pooled */	rdrobust ins_ind	force_shift		, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_1})
	/* Rural */		rdrobust ins_ind	force_shift		if rural==1 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_1})
	/* Urban */		rdrobust ins_ind	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_0})
	// d) Selection component (Column 8)
	/* Urban */	rdrobust hh_size	force_shift		if rural==0 & ins_ind==1 , c(0.00000000001) p(1) bwselect($bwc)kernel($kernel) vce(cluster comcount)  
	restore
	
	preserve 
	// b) Population (Columns 4-6)
	/* Pooled */	rdrobust insured	force_shift					, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_1} ${cFE_0})
	/* Rural */		rdrobust insured	force_shift		if rural==1	, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_1})
	/* Urban */		rdrobust insured	force_shift		if rural==0	, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) covs(${cFE_0})
	// c) Intensive margin	(Column 7)		
	/* Urban */		rdrobust insured	force_shift		if rural==0 & ins_ind==1, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount)
	restore
	
*	TABLE 4: Subsidization and enrollment by household head characteristics
	foreach sel in mrd_hhh 	wdw_hhh_male fem_head 	eld_hhh_male eld_hhh_fem	prim_hhh_male	prim_hhh_fem {
	use "$data/hhh_09_10.dta", clear
	display "----------------"
	display "`sel'"
	display "----------------"	
	rdrobust ins_ind	force_shift		if rural==0 & `sel'==1 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount)	
	}	

*	TABLE 5: Subs and individual enrollment by demogr characteristics 
	foreach sel in  nadult_f nadult_m 	employable_f employable_m 	elderly_f elderly_m {	
	use "$data/slct_09_10.dta", clear
	display "--------------"
	display "`sel'"
	display "--------------"
	rdrobust insured	force_shift		if rural==0 & `sel'==1		, c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) ///
	covs(comm29	comm30 comm31	comm32	comm33	comm34	comm35 	comm36	comm37	comm38	comm39	comm40	comm41	comm42	comm43	comm44	comm45	comm46	comm47	comm48 comm49)
	}	

*	TABLE 6: Adverse Selection
	use "$data/adv_09_12.dta", clear
	// Health care facility visits:
	/* Without controls */ 	rdrobust visits_ind	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount)
	/* With controls */		rdrobust visits_ind	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) 	covs(female employable elderly)
	
	// Health insurance claims:
	/* Without controls */ 	rdrobust valtot_ind	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount)
	/* With controls */		rdrobust valtot_ind	force_shift		if rural==0 , c(0.00000000001) p(1) bwselect($bwc) kernel($kernel) vce(cluster comcount) 	covs(female employable elderly)
	
*	TABLE 7: Role of structural difference
	use "$data/wlth_09_10.dta", clear
	// 1. RDD w. comm-wealth interaction
		reg ins_ind 	elig_med rural r_elig_med	pcaw_p20_pl	w_elig_med 	force_shift medr_elig		 /// 
					[pw=kern]  if force_shift>-0.07 & force_shift<0.22 , vce(cluster comcount)
		test pcaw_p20_pl rural
	
	// 2. RDD w. comm.-hhsize interaction
		reg ins_ind 	elig_med  rural r_elig_med 		hh_size_p20	h_elig_med 	force_shift medr_elig /// 
					[pw=kern]  if force_shift>-0.07 & force_shift<0.22 , vce(cluster comcount)
		test hh_size_p20 rural
					
	// 3. RDD w. comm.-educ interaction
		reg ins_ind 	elig_med 	rural r_elig_med	sum_lit_p20	l_elig_med 		force_shift medr_elig /// 
					[pw=kern]  if force_shift>-0.07 & force_shift<0.22 , vce(cluster comcount)
		test sum_lit_p20 rural

	// 4. RDD w. CSPS-distance interaction
		reg ins_ind 	elig_med 	rural r_elig_med	csps_dist d_elig_med 	 force_shift medr_elig /// 
					[pw=kern]  if force_shift>-0.07 & force_shift<0.22 , vce(cluster comcount)
		test csps_dist rural

	